<?php
require_once(dirname(dirname(__FILE__)) . '/app.php');

need_login();

$daytime = strtotime(date('Y-m-d'));
$condition = array( 'to_user_id' => $login_user_id, );
$selector = strval($_GET['s']);

if ( $selector != 'consume' ) {
	$condition['end_time'] > "{$daytime}";
	$condition['consume'] = 'N';
	$selector = 'index';
}
else {
	$condition['or'] = array('consume' => 'Y', "end_time <= {$daytime}");
}

$count = Table::Count('card', $condition);
list($pagesize, $offset, $pagestring) = pagestring($count, 10);
$cards = DB::LimitQuery('card', array(
	'condition' => $condition,
	'order' => 'ORDER BY end_time DESC, begin_time ASC',
	'size' => $pagesize,
	'offset' => $offset,
));

$pagetitle = '代金券';

include template('account_card');